package com.atguigu.gmall.product.api;

import com.atguigu.gmall.product.model.*;
import com.atguigu.gmall.product.service.BaseAttrInfoService;
import com.atguigu.gmall.product.service.BaseCategoryViewService;
import com.atguigu.gmall.product.service.SkuManageService;
import com.atguigu.gmall.product.service.SpuManageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;


@RestController
@RequestMapping("/api/product")
public class ProductApiController {

    @Autowired
    private SkuManageService skuManageService;

    @Autowired
    private SpuManageService spuManageService;

    @Autowired
    private BaseCategoryViewService baseCategoryViewService;

    @Autowired
    private BaseAttrInfoService baseAttrInfoService;

   // 获取商品信息 包含商品图片

    @GetMapping("/inner/getSkuInfo/{skuId}")
    public SkuInfo getSkuInfo(@PathVariable("skuId") Long skuId) {
        SkuInfo skuInfo = SkuManageService.getSkuInfo(skuId);
        return skuInfo;
    }

    //根据三级分类ID 查询所属所有三级分类信息

    @GetMapping("/inner/getCategoryView/{category3Id}")
    public BaseCategoryView getCategoryView(@PathVariable("category3Id") Long category3Id) {
        BaseCategoryView baseCategoryView = baseCategoryViewService.getById(category3Id);
        return baseCategoryView;
    }


    //根据skuID查询商品价格

    @GetMapping("/inner/getSkuPrice/{skuId}")
    public BigDecimal getSkuPrice(@PathVariable("skuId") Long skuId) {
        BigDecimal priceBigDecimal = skuManageService.getSkuPrice(skuId);
        return priceBigDecimal;
    }


    //根据SPUID查询商品所有海报列表

    @GetMapping("/inner/findSpuPosterBySpuId/{spuId}")
    public List<SpuPoster> getSpuPosterBySpuId(@PathVariable("spuId") Long spuId) {
        List<SpuPoster> spuPosterList = spuManageService.getSpuPosterBySpuId(spuId);
        return spuPosterList;
    }

    //根据商品SkuID查询当前sku商品所有平台属性名称包含属性值

    @GetMapping("/inner/getAttrList/{skuId}")
    public List<BaseAttrInfo> getAttrList(@PathVariable("skuId") Long skuId) {
        List<BaseAttrInfo> list = baseAttrInfoService.getAttrList(skuId);
        return list;
    }

    //查询SPU所有销售属性,将指定传入SKU商品销售属性区分是否选中

    @GetMapping("/inner/getSpuSaleAttrListCheckBySku/{skuId}/{spuId}")
    public List<SpuSaleAttr> getSpuSaleAttrListCheckBySku(
            @PathVariable("skuId") Long skuId,
            @PathVariable("spuId") Long spuId) {
        List<SpuSaleAttr> list = spuManageService.getSpuSaleAttrListCheckBySku(skuId, spuId);
        return list;
    }


    //查询每个商品SKU 销售属性 跟 SKUID 对照关系

    @GetMapping("/inner/getSkuValueIdsMap/{spuId}")
    public Map getSkuValueIdsMap(@PathVariable("spuId") Long spuId) {
        Map<String, String> valueJsonMap = spuManageService.getSkuValueIdsMap(spuId);
        return valueJsonMap;
    }
}
